﻿@using System.Text.RegularExpressions;

@model NccPost

@{  
    var postDetails = ViewHelper.GetCurrentLanguagePostDetails(Model, ViewBag.CurrentLanguage, true);
    var isSticky = "icon-pin-classic";

    if (postDetails != null)
    {

        <div style="border: dashed 1px gray;padding:10px 10px;">
            @if (Model.ThumImage != null)
            {
                <div style="width:220px; float:left; margin-right:10px;">
                    <img src="@Model.ThumImage" width="220" height="110" />
                </div>
            }
            <div>
                <a href="/Post/@postDetails.Slug"><h3 style="margin-top:0px;">@postDetails.Title</h3></a>
                <p style="font-style:italic; font-size:12px;">
                    @_T["Author"]:
                    @if (Model.Author != null)
                    { <span>@Model.Author.FullName</span> }
                    else
                    {<span>@_T["Anonymous"]</span> }
                    <span> | @_T["Published Date"]: @Model.PublishDate.ToString("MMM dd, yyyy") </span>

                    @*| <a href = "#"> @Model.Comments.Count() @_T["Comments"] </a>*@
                    @*| <i class="icon-share"></i> <a href="#">39 Shares</a>*@
                    @if (Model.Categories.Count > 0)
                    {
                        <span>| @_T["Category"] :</span>
                                @foreach (NccPostCategory cat in Model.Categories)
                                {
                                    NccCategoryDetails cDetails = cat.Category.CategoryDetails.Where(x => x.Language == ViewBag.CurrentLanguage).FirstOrDefault();
                                    if (cDetails == null)
                                    {
                                        cDetails = cat.Category.CategoryDetails.FirstOrDefault();
                                    }
                                    <a href="/Category/Index/?slug=@cDetails.Slug"><span class="label label-primary">@cDetails.Name</span></a>
                                }
                    }
                    @if (Model.Tags.Count > 0)
                    {
                        <span>| @_T["Tags"] :</span>
                                @foreach (NccPostTag tag in Model.Tags)
                                {
                                    <a href="/Tags/Index/?name=@tag.Tag.Name"><span class="label label-info">@tag.Tag.Name</span></a>
                                }
                    }
                </p>

                <hr style="margin:0px;padding:0px;" />
                @{
                    var content = postDetails.Content;
                    if (content?.Length > 0)
                    {
                        content = Regex.Replace(content, "<[^>]*>", string.Empty);
                    }
                    if (content?.Length > 0)
                    {
                        content = Regex.Replace(content, @"^\s*$\n", string.Empty, RegexOptions.Multiline);
                    }
                    var len = content?.Length;
                    if (len > 200)
                    {
                        len = 200;
                        content = content.Substring(0, len);
                    }
                    <p>@Html.Raw(content) ...<a href="/Post/@postDetails.Slug">@_T["More"]</a></p>
                }
            </div>
        </div>
        <br />
    }
}